package servlet;

import bean.Movie;
import service.impl.MovieServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;

@WebServlet("/admin/admin_modify_movie")
public class AdminModifyMovie extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8"); // 设置请求编码为UTF-8
        response.setContentType("text/html;charset=UTF-8"); // 设置响应内容类型和编码
        String movieIdStr = request.getParameter("movieId");
        int movieId = Integer.parseInt(movieIdStr);
        String name = request.getParameter("name");
        String type = request.getParameter("type");
       // String img = request.getParameter("img");
       // System.out.println(img);
        String mainActor = request.getParameter("main_actor");
        String upTime = request.getParameter("upTime");
        String totalTime = request.getParameter("totalTime"); // 注意这里与参数名匹配
        System.out.println(totalTime);
        String price = request.getParameter("price");
        MovieServiceImpl movieService = new MovieServiceImpl();
        Movie movie = new Movie();
        movie.setId(movieId);
        movie.setName(name);
        movie.setType(type);
       // movie.setImg(img);
        movie.setMain_actor(mainActor);
        movie.setDate(upTime);

        movie.setTotalTime(Long.parseLong(totalTime));
        movie.setPrice(new BigDecimal(price));
        movieService.modifyMovie(movie);
    }
}
